<?php
namespace app\tour\model;

use think\Model;
use think\Db;
use think\Session;

class Ticket extends Model
{

    /**
     * @return false|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    static function getTicketList(){

        $tour_id = Session::get('tour_id');
       
        $data = Db::name('tour_ticket')
                    ->alias('t1')
                    ->field('t1.*,t3.t_admin_tel,t3.admin_rename')
                    ->join('lv_tour_admin t3','t1.tadmin_id = t3.t_admin_id')
                    ->where('t1.tour_id',$tour_id)
                    ->order('sort desc,tid desc')
                    ->select();

        return $data;

    }

    /**
     * @return false|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    static function getCategoryList(){

        $tour_id = Session::get('tour_id');

        return Db::name('tour_ticket_category')
                    ->alias('t1')
                    ->field('t1.*,t2.t_admin_tel')
                    ->where('t1.tour_id',$tour_id)
                    ->where('t1.is_del',0)
                    ->join("lv_tour_admin t2",'t1.tadmin_id = t2.t_admin_id','left')
                    ->order('sort desc,cid desc')
                    ->select();

    }

    /**
     * @param $data
     * @return int|string
     */
    static function addCategory($data){

        return Db::name('tour_ticket_category')->insert($data);

    }

    /**
     * @param $id
     * @param $editData
     * @return int|string
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     */
    static function editCategory($id,$editData){

        return Db::name('tour_ticket_category')->where("cid",$id)->update($editData);

    }

    /**
     * @param $addData
     * @return int|string
     */
    static function addTicket($addData){

        return Db::name('tour_ticket')->insertGetId($addData);

    }

    static function editTicket($tid,$editData){

        $res = Db::name('tour_ticket')->where('tid',$tid)->update($editData);

        return $editData;

    }
}
